/**
 * @author 黄波
 * 创建日期：2011Aug 28, 2011
 * TODO// N/A
 */
package com.platform.manager.action;

import java.util.ArrayList;
import java.util.List;

import com.platform.bean.TreeBean;
import com.platform.manager.bo.ModuleBo;
import com.platform.pojo.Module;

//根据父节点ID，返回子节点列表
public class ModuleNodeAction extends ManagerSupport {

	private List<TreeBean> beans;	//返回信息，节点列表
	private boolean success;	//返回信息。标识回调情况
	private String node;//父节点ID,通过FireBug调试，可看到此值
	
	/**
	 * @return the node
	 */
	public String getNode() {
		return node;
	}
	/**
	 * @param node the node to set
	 */
	public void setNode(String node) {
		this.node = node;
	}
	/**
	 * @return the beans
	 */
	public List<TreeBean> getBeans() {
		return beans;
	}
	/**
	 * @param beans the beans to set
	 */
	public void setBeans(List<TreeBean> beans) {
		this.beans = beans;
	}
	/**
	 * @return the success
	 */
	public boolean isSuccess() {
		return success;
	}
	/**
	 * @param success the success to set
	 */
	public void setSuccess(boolean success) {
		this.success = success;
	}
	
	@Override
	public String execute() throws Exception {
		ModuleBo bo = new ModuleBo();
		List<Module> childrenModules = bo.getChildModules(node);
		//将modules转化为beanlist
		for(Module module : childrenModules) {
			TreeBean bean = new TreeBean();
			bean.setId(module.getId().toString());
			bean.setText(module.getModuleName());
			if(bo.getChildModules(module.getId().toString()).size() > 0) {
				//该节点有子节点，则表示非叶子节点
				bean.setLeaf(false);
			} else {
				bean.setLeaf(true);
			}
			bean.setExpanded(false);
			if(beans == null) {
				beans = new ArrayList<TreeBean>();
			}
			beans.add(bean);
		}
		success = true;
		return SUCCESS;
	}
	
}
